package cn.zn.modules.pz.enums;

import cn.hutool.core.collection.CollUtil;
import cn.zn.framework.common.vo.ComboxItemVO;
import lombok.Getter;

import java.util.List;

@Getter
public enum SpendingTypeEnum {
    /**
     * 一般
     */
    type_1(1, "一般", false, "经费"),
    type_2(2, "出差", false, "经费"),
    type_3(3, "专家", false, "专家经费"),
    type_4(4, "补登", false, "经费"),
    type_5(5, "提现", true, "经费"),
    type_6(6, "专项", false, "专项经费");

    private Integer code;
    private String name;
    private Boolean canNoBudget;
    /**
     * 经费名称，打印时展示使用：经费、专家经费、专项经费
     */
    private String spendingName;

    SpendingTypeEnum(Integer code, String name, Boolean canNoBudget, String spendingName) {
        this.code = code;
        this.name = name;
        this.canNoBudget = canNoBudget;
        this.spendingName = spendingName;
    }

    public static SpendingTypeEnum findByCode(int code) {
        for (SpendingTypeEnum e : values()) {
            if (e.getCode() == code) {
                return e;
            }
        }
        return null;
    }

    /**
     * 可选择的经费类型集合
     *
     * @param showZj 是否显示专家
     * @param showZx 是不显示专项
     * @param showTx 是否显示提现
     * @return
     */
    public static List<ComboxItemVO> buildCombox(Boolean showZj, Boolean showZx, Boolean showTx) {
        List<ComboxItemVO> list = CollUtil.newArrayList();
        SpendingTypeEnum spendingTypeEnum;
        for (int i = 0; i < values().length; i++) {
            spendingTypeEnum = values()[i];
            if (spendingTypeEnum.getCode() == 3 && !showZj) {
                continue;
            }
            if (spendingTypeEnum.getCode() == 6 && !showZx) {
                continue;
            }
            if (spendingTypeEnum.getCode() == 5 && !showTx) {
                continue;
            }
            list.add(ComboxItemVO.builder()
                    .value(spendingTypeEnum.code)
                    .text(spendingTypeEnum.name)
                    .build());
        }
        return list;
    }

}
